<template>
	<view class="container">

		<scroll-view style="height: calc(100% - 106rpx)" scroll-y @scrolltolower="loadMoreData">
			<view v-for="(item, index) in accountList" :key="index" @click="toDetail(item)" class="card">
				<img src="/static/icon/yl_icon.png" class="logo" />
				<view>
					<view class="row">
						<!-- <view class="bank-name">{{ item.bankName }}</view> -->
						<view class="default"> 储蓄卡 </view>
					</view>
					<!-- <view class="type">
						{{ item.defaultCard === 1 ? '默认结算卡' : '' }}
					</view> -->
					<view class="no">{{ encryptNo(item.accountNo) }}</view>
					<view class="name">
						{{item.accountName}}
					</view>
				</view>
			</view>
		</scroll-view>
	</view>

	<!-- <DragButton :isDock="true" imageUrl="https://jhl-pay.oss-cn-shenzhen.aliyuncs.com/agent/ico-btn-add.png" @btnClick="
		navigate(
			`/authentication/addBank/index`
		)
		" /> -->
</template>

<script setup>
	import {
		ref
	} from "vue";
	import {
		queryReport
	} from "@/api/common.js";
	import {
		bankCardList
	} from "@/api/mine.js";
	import {
		showToast
	} from "@/utils/toast";
	import {
		navigate
	} from "@/utils/router";
	import {
		onLoad,
		onShow
	} from "@dcloudio/uni-app";
	import DragButton from "@/components/button/drag-button/index.vue";
	import {
		useStore
	} from "@/store";
	const store = useStore();
	// 报表查询条件
	let queryParams = ref({
		id: 1001,
		page: 1,
		size: 20,
		conditions: [{
			code: "userId",
			operator: "eq",
			value: store.userInfo.id
		}],
		oemUserNo: 'BU100002'
	});
	// 银行卡总数
	let total = ref(0);
	// 账户列表
	let accountList = ref([

	]);
	let settleStatus = ref(null);
	// 代理名称、身份证号
	let agentInfo = ref({});

	onLoad((options) => {
		agentInfo.value = options;
	});

	onShow(() => {

		getAccountList();
	});

	// 查询账户列表
	function getAccountList() {
		bankCardList(store.userInfo.userId, "JSK").then((res) => {

			total.value = res.length;
			accountList.value = res;

			settleStatus = res.length > 0 ? "1" : "0";

			uni.setStorageSync("settleStatus", settleStatus);
		
		});
	}
	


	// 加载下一页
	function loadMoreData() {
		if (queryParams.value.page * queryParams.value.size < total.value) {
			queryParams.value.page++;
			getAccountList();
		} else {
			showToast("没有更多数据了");
		}
	}

	// 加密银行卡号
	function encryptNo(no) {
		const length = no.length;
		const remainder = length % 4;
		const startIndex = length - (remainder === 0 ? 4 : remainder);
		const lastFourNo = no.substring(startIndex, length);
		return (
			"**** ".repeat(remainder === 0 ? length / 4 - 1 : length / 4) + lastFourNo
		);
	}

	// 跳转至账户详情页
	function toDetail(item) {
		uni.navigateTo({
			url: "/authentication/realBank/cardDetail/index?item=" + encodeURIComponent(JSON.stringify(item)),
		});
	}
</script>

<style>
	Page {
		background: white;
	}
</style>
<style lang="scss" scoped>
	@import './index.scss';
</style>